import request from './request'

// 购物车商品接口类型定义
export interface CartItem {
  id?: number
  userId: number
  productId: number
  productName?: string
  productImage?: string
  price?: number
  quantity: number
  checked?: boolean
}

// 获取购物车列表
export const getCartList = (userId: number) => {
  return request({
    url: '/cart',
    method: 'get',
    params: { userId }
  })
}

// 添加商品到购物车
export const addToCart = (userId: number, productId: number, quantity: number) => {
  return request({
    url: '/cart/add',
    method: 'post',
    params: { userId, productId, quantity }
  })
}

// 更新购物车商品数量
export const updateCart = (userId: number, productId: number, quantity: number) => {
  return request({
    url: '/cart/update',
    method: 'put',
    params: { userId, productId, quantity }
  })
}

// 删除购物车商品
export const removeCartItem = (userId: number, productId: number) => {
  return request({
    url: '/cart/remove',
    method: 'delete',
    params: { userId, productId }
  })
}

// 清空购物车
export const clearCart = (userId: number) => {
  return request({
    url: '/cart/clear',
    method: 'delete',
    params: { userId }
  })
}